import { message, Popconfirm } from 'antd';
import React from 'react';
import { deleteUser } from '../../services/userServices';

class DeleteUser extends React.PureComponent {
  constructor(props) {
    super(props);
  }

  deleteConfirm = async () => {
    message.success('Click on Yes');
    try {
      await deleteUser(this.props.userId);
      message.info('User deleted successfully');
      this.props.onDeleteSuccess(this.props.userId);
    } catch (error) {
      message.error(error.message || 'Failed to delete user');
    }
  };

  deleteCancel = () => {
    message.error('Click on No');
  };

  render() {
    return (
      <>
        <Popconfirm
          title="你确定删除这个用户吗?"
          onConfirm={this.deleteConfirm}
          onCancel={this.deleteCancel}
          okText="Yes"
          cancelText="No"
        >
          <a href="#">删除</a>
        </Popconfirm>
      </>
    );
  }
}

export default DeleteUser;
